<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: Muerzhi
  Date: 2023/12/26
  Time: 15:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册账号</title>
</head>
<body>
<%
    String account=request.getParameter("newAccount");
    String password1=request.getParameter("password1");

    Class.forName("com.mysql.cj.jdbc.Driver");
    String url="jdbc:mysql://localhost:3306/library";
    String username="root";
    String password="17876724541";
    Connection conn = DriverManager.getConnection(url,username,password);

    String sql="INSERT INTO user(account,password) values(?,?)";
    PreparedStatement ps =conn.prepareStatement(sql);

    ps.setString(1,account);
    ps.setString(2,password1);
    int i=ps.executeUpdate();
    if (i!=0){
        out.println("<script>");
        out.println("alert('账号"+account+"注册成功,快去登录吧！');");
        out.println("location.href='login.jsp'");
        out.println("</script>");
    }else{
        out.println("<script>");
        out.println("alert('注册失败');");
        out.println("location.href='login.jsp'");
        out.println("</script>");
    }
    ps.close();
    conn.close();
%>
</body>
</html>
